import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';
import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { getClCoordinateData } from '@gis/lib/api';

const typeCodeEnum = { zz_02_01: 'xfc', zz_02_02: 'zaxl', zz_02_03: 'zhzfc' };

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    /* this.type: 这个type主要用于筛选,需要和filter-legend里面的type相对应 */
    this.type = typeCodeEnum[data.type_code];
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  onClick(e) {}
}

export default class Cl extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const params = {
      dType: 'cl',
      area_code: area_code,
    };
    const data = await handleCommonRes(getClCoordinateData, params);
    // const data = [
    //   {
    //     unit_name: '东升街道办',
    //     last_activity_time: '2021-06-23 19:24:17',
    //     latitude: '30.56099715',
    //     name: 'XF.村社03',
    //     online: 0,
    //     id: '8a8080f370c2554a0170c25b77aa0451',
    //     equipment_identification: '027021654876',
    //     longitude: '103.93084353',
    //     type_code: 'zz_02_01',
    //   },
    // ];
    return data.map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
